package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.common.exception.LyException;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <h3>leyou-project</h3>
 * <p></p>
 *
 * @author : hhw
 * @date : 2020-05-26 13:56
 **/
@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper, SpecParam> implements SpecParamService {



    @Override
    public List<SpecParam> querySpecParams(Long cid, Long gid, Boolean searching) {
        //健壮性判断
        if (cid == null && gid == null){
            throw new LyException(400, "请求参数不能为空");
            //400为无效的请求,401位未授权,403为授权了但权限不够
        }
        List<SpecParam> list = query().eq(cid != null, "category_id", cid)
                .eq(gid != null, "group_id", gid)
                .eq(searching != null, "searching", searching)
                .list();

        return list;
    }
}
